#!  python
# -*- coding: UTF-8 -*-
'''
@Author ：Star
@Date ：2022/10/14  
'''
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
import random

op = webdriver.ChromeOptions()
op.add_experimental_option("excludeSwitches", ["enable-automation"])
op.add_experimental_option("useAutomationExtension", False)
driver = webdriver.Chrome(options=op)
driver.get(r"http://wwww.baidu.com")

searh=driver.find_element(By.CSS_SELECTOR,"#kw")
searh.send_keys("自动化")
sleep(2)
randomNum = random.randint(1,10)
print(randomNum)
for i in range(randomNum):
    searh.send_keys(Keys.DOWN)
    sleep(1)
sleep(2)
searh.send_keys(Keys.ENTER)
print(searh.get_attribute("value"))
sleep(2)
assert searh.get_attribute("value") in driver.page_source

print("success")
driver.quit()